package com.deer.wms.ureport.web;


import com.bstek.ureport.Utils;
import com.bstek.ureport.export.ExportManager;
import com.bstek.ureport.export.html.HtmlReport;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;
import com.deer.wms.ureport.model.LoadModel;
import com.deer.wms.ureport.model.UreportFile;
import com.deer.wms.ureport.service.UreportFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by guo on 2019/11/21.
 */
@Api(description = "Ureport接口")
@RestController
@RequestMapping("/ureports")
public class UreportController {


    @Autowired
    private UreportFileService ureportFileService;



    @ApiOperation(value = " ", notes = " ")
    @PostMapping("/loadReport")
    public Result loadReport(@RequestBody LoadModel loadModel ) {
        ExportManager exportManager=(ExportManager) Utils.getApplicationContext().getBean(ExportManager.BEAN_ID);
        HtmlReport htmlReport = exportManager.exportHtml("mysql:"+loadModel.getFileName(),"/wms",loadModel.getParameters());

        return ResultGenerator.genSuccessResult(htmlReport.getContent());
    }



    @GetMapping("/findAll")
    public Result findAll( ) {
        List<UreportFile> list = ureportFileService.list();
        return ResultGenerator.genSuccessResult(list);
    }


}
